package DailyPractice.Day24;

import java.util.*;

/**
 * @author lumin
 * @date 2022/05/20 21:29
 **/
public class Num2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[][] arr = new int[m][n];
        sc.nextLine();//用来跳过行列后的回车符
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                arr[i][j] = sc.nextInt();
            }
        }
        ArrayList<ArrayList<Integer>> ret = new ArrayList<>();
        dfs(ret,arr,0,0);
        System.out.println(ret);
    }

    private static void dfs(ArrayList<ArrayList<Integer>> ret, int[][] arr, int m, int n) {
        int i = 0;

        while(i < arr.length){
            int j = 0;
            while(j < arr[0].length){
                if(arr[i][j] == 0){
                    ArrayList<Integer> list = new ArrayList<>();
                    list.add(arr[i][j]);
                    ret.add(list);
                }else{
                    dfs(ret,arr,i,j + 1);
                    dfs(ret,arr,i + 1,j);
                    ret.remove(ret.size() - 1);
                }
                j++;
            }
            i++;
        }
    }
}